clear all;

data.gini_mean=[0.232443651571487	0.236453048605833	0.237373136331131	0.246941947699751	0.252044403744002	0.258646256492527];
data.std_data=[0.3200123156191	0.327477132261793	0.365478526307977	0.369745236330101	0.352831666059292	0.343834580040610];
model=load('model\result_baseline.mat');
credit=load('model\result_credit.mat');
deposit=load('model\result_deposit.mat');

xdata=[86,88,90,92,94,96];
xmodel=86:1:96;

figure('Position',[20,40,950,340],'Color',[1,1,1])
subplot(1,2,1)

plot(1e10,1e10,'-b','linewidth',2)
hold on
plot(1e10,1e10,'-.r','linewidth',2)
plot(1e10,1e10,':g','linewidth',2)
plot(1e10,1e10,'--k','linewidth',2)

% axis square
yyaxis left
plot(xmodel,model.gini_within_overall(1:11),'-b','linewidth',2)
hold on
yyaxis right
plot(xdata,data.gini_mean,'--k','linewidth',2)
hold on
yyaxis left
plot(xmodel,credit.gini_within_overall(1:11),'-.r','linewidth',2)
hold on
plot(xmodel,deposit.gini_within_overall(1:11),':g','linewidth',2)
xlabel('year', 'FontSize',12,'Interpreter','Latex');
ylabel('income Gini within markets', 'FontSize',12,'Interpreter','Latex');
legend('model','credit channel','deposit channel','data',...
    'interpreter','latex','location',[0.204 0.771 0 0],'Numcolumns',1)
xlim([86 96]);
set(gca,'FontSize',11);
title( 'A. Income Gini within markets', 'FontSize',13,'Interpreter','Latex');
ax = gca;
ax.YAxis(1).Color = 'b';
ax.YAxis(2).Color = 'k';


a=mean(model.gini_within_overall(1:11));
b=mean(data.gini_mean);

yyaxis left
yl1=[0.138,0.18];
ytic1=0.14:0.01:0.18;
ylim(yl1);
yticks(ytic1);
yyaxis right
yl2=yl1+b-a;
ylim(yl2)
ntick=length(ytic1);
ytic2=ytic1+b-a;
ytic2_label=cell(ntick,1);
for i=1:ntick
    ytic2_label{i}=strcat(num2str(ytic1(i)),strrep(num2str(floorS(b-a,2),'%+.2f'),'0.','.'));
end
yticks(ytic2);
set(gca,'ytick',ytic2,'yticklabel',ytic2_label)
















xdata=[86,88,90,92,94,96];
xmodel=86:1:96;



subplot(1,2,2)
% axis square
yyaxis left
plot(xmodel,model.std_model(1:11),'-b','linewidth',2)
hold on
yyaxis right
plot(xdata,data.std_data,'--k','linewidth',2)
hold on
yyaxis left
plot(xmodel,credit.std_model(1:11),'-.r','linewidth',2)
hold on
plot(xmodel,deposit.std_model(1:11),':g','linewidth',2)
xlabel('year', 'FontSize',12,'Interpreter','Latex');
ylabel('SD of $\log$ income per capita', 'FontSize',12,'Interpreter','Latex');
% title( 'B. SD of $\log$(income per capita) across markets', 'FontSize',15,'Interpreter','Latex');
xlim([86 96]);
set(gca,'FontSize',11);
title( [{'B. SD of $\log$ income per capita'},{'across markets'}], 'FontSize',13,'Interpreter','Latex');
ax = gca;
ax.YAxis(1).Color = 'b';
ax.YAxis(2).Color = 'k';

a=mean(model.std_model(1:11));
b=mean(data.std_data);

yyaxis left
yl1=[0.34,0.4];
ytic1=0.34:0.02:0.4;
ylim(yl1);
yticks(ytic1);
yyaxis right
yl2=yl1+b-a;
ylim(yl2)
ntick=length(ytic1);
ytic2=ytic1+b-a;
ytic2_label=cell(ntick,1);
for i=1:ntick
    ytic2_label{i}=strcat(num2str(ytic1(i)),strrep(num2str(floorS(b-a,2),'%+.2f'),'0.','.'));
end
yticks(ytic2);
set(gca,'ytick',ytic2,'yticklabel',ytic2_label)
